import {Empty} from "antd";
import React from "react";
import {Component} from "react";
import {
    GET_CHAPTER_DETAILES,
    GET_COURSE_TEACHERS,
    GET_COURSE_DOCS,
    GET_ARTICLE_DETAILES,
    GET_ARTICLE_RECORD
} from "../../api/APIURLDefine";
import {AxioInstance} from "../../api/AxiosHelper";
import './index.less'

export default class ArticleLesson extends Component<any, any> {
    state = {
        lessonDara: null,
        record: null
    }

    componentDidMount() {
        var params = new URLSearchParams(this.props.history.location.search);
        var id = 1;
        if (params.has("id")) {
            id = parseInt(params.get("id"));
        }

        AxioInstance.get(`${GET_CHAPTER_DETAILES}/${id}`).then((data: any) => {
            if (data.lessonDetails) {
                AxioInstance.get(`${GET_ARTICLE_DETAILES}/${data.lessonDetails.articleId}`).then((res) => {
                    this.setState({lessonDara: res})
                })
            }
            AxioInstance.get(`${GET_ARTICLE_RECORD}/1`).then((resp) => {
                //console.log(resp)
                this.setState({record: resp})
            })
        });
    }

    render() {
        return (
            <div className="article-back">
                <div className="article-container">
                    <div className="article-header">
                        <div className="article-title">
                            {this.state.lessonDara?.title}
                        </div>
                        <div className="article-author">
                            授课老师:{this.state.lessonDara?.author} &emsp; 访问量:{this.state.record?.invited}
                        </div>
                    </div>
                    <div className="article-body" dangerouslySetInnerHTML={{__html: this.state.lessonDara?.content}}>
                    </div>
                </div>

            </div>
        );
    }

}
